package de.tabuma.customer.logik;

import de.tabuma.customer.entity.*;

import java.util.*;
import java.util.logging.*;

/**
 *
 * @author alefen
 */
public class CustomerFacade {

    private static final Logger log = Logger.getLogger(CustomerFacade.class.getName());

    public static int create(Customer customer, String user) {
        return (int) PMF.doCreate(customer, user);
    }
    
    public static Customer get(int id) {
        return PMF.get(id, new Customer());
    }
    
    public static void update(Customer customer, String user) {
        PMF.doUpdate(customer, user);
    }
    
    public static void remove(Customer customer, String user) {
        Long id = customer.getId();
        PMF.doRemove(customer, user);
        List<CustomerUserRelation> curList = CustomerUserRelationFacade.getList1(id.intValue());
        for(int i=0;i<curList.size();i++) {
            CustomerUserRelationFacade.remove(curList.get(i), user);
        }
    }

    public static List<Customer> getCustomer(String user) {

        String keys[] = new String[1];
        keys[0] = "user";
        String values[] = new String[1];
        values[0] = user;

        List<Customer> cList = new ArrayList<Customer>();
        List<CustomerUserRelation> list = CustomerUserRelationFacade.getList(user);
        for(int i=0;i<list.size();i++) {
            CustomerUserRelation cur = list.get(i);
            Customer customer = PMF.get(cur.getCostumerId(), new Customer());
            cList.add(customer);
        }
        return cList;
        
    }
}
